	$('#historic-prices-start-month, #historic-prices-start-year').change(function () {
		var day = $('#historic-prices-start-day').val();
		var month = $('#historic-prices-start-month').val();
		var year = $('#historic-prices-start-year').val();

		$('#historic-prices-start-day').html(generateDaySelection(day, month, year));
	});
	

	$('#historic-prices-end-month, #historic-prices-end-year').change(function () {
		var day = $('#historic-prices-end-day').val();
		var month = $('#historic-prices-end-month').val();
		var year = $('#historic-prices-end-year').val();

		$('#historic-prices-end-day').html(generateDaySelection(day, month, year));
	});
	

	function daysInMonth(month, year) {
		return new Date(year, month, 0).getDate();
	}

	function generateDaySelection(day, month, year) {
		var numberOfDaysInMonth = daysInMonth(month, year);

		if (day > numberOfDaysInMonth) {
			day = numberOfDaysInMonth;
		}

		var newDaySelection = '';
		for (var counter = 1; counter <= numberOfDaysInMonth; counter++) {
			if (counter == day) {
				newDaySelection += '<option selected=\"selected\" value=\"' + counter + '\">' + counter + ' .</option>';
			}
			else {
				newDaySelection += '<option value=\"' + counter + '\">' + counter + ' .</option>';
			}
		}
		return newDaySelection;
	}
	

	$('#request-historic-price').click(function () {
		requestHistoricPrice();
	});

	$('.js-historic-date-selection select').keypress(function (e) {
		if (e.which == 13) {
			requestHistoricPrice();
			return false;
		}
	});

	function requestHistoricPrice() {

		var requestedStockMarket = $('#historic-prices-stock-market').val();
		var requestedStartDate = $('#historic-prices-start-day').val() + "." + $('#historic-prices-start-month').val() + "." +
			$('#historic-prices-start-year').val();
		var requestedEndDate = $('#historic-prices-end-day').val() + "." + $('#historic-prices-end-month').val() + "." +
			$('#historic-prices-end-year').val();
		var decodedUri = decodeURIComponent("%2fkurse%2fhistorisch%2fGoogle%2f");
		window.location = decodedUri + requestedStockMarket + "/" + requestedStartDate + "_" + requestedEndDate;
	};